﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Campus.Main.Basic.InsertValues;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic.Settings
{
    public partial class FakultyForm : DefaultForm
    {
        public FakultyForm():base()
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            ContextMenuStrip = contextMenuStrip1;
            contextMenuStrip1.Click += ToolStripMenuItem_Click;
        }
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int current = dataGridView1.CurrentCell.RowIndex;
            string id = Convert.ToString(dataGridView1.Rows[current].Cells[0].Value);
            if (MessageBox.Show("Silmek istiyormusunuz?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                aToDb.DeleteTable("fakulty", "id", id);
                MessageBox.Show("Silindi");
                Initialize();
            }
        }
        public override void Initialize()
        {
            MaximizeBox = false;
            aToDb.AddItemDBGridView(dataGridView1,Query.Fakulty);
            ControlComponent.UnVisibleCells(dataGridView1,0);
        }

        private void FakultyForm_Load(object sender, EventArgs e)
        {
            textBox1.Focus();
            Initialize();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                aToDb.InsertIntoTable("Fakulty", "Description", textBox1.Text);
                Initialize();
                textBox1.Clear();
            }
            else
            {
                MessageBox.Show("Талаадарды толтургула!!!");
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var a = new List<string>();
            ControlComponent.AddToList(a,dataGridView1,e,0,1);
            Fakulty f = new Fakulty(a);
            f.FormClosed += Bind;
            f.ShowDialog();
        }

        private new void Bind(object sender, FormClosedEventArgs e)
        {
            Initialize();
        }
    }
}
